﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WF.Common;
using Com.DAO;

namespace WF.Web.Components.WorkSpace
{
    public partial class HolidayList : BaseUserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.DataManager.Close();
            this.DataManager.Open(System.Configuration.ConfigurationManager.AppSettings.Get("KQConnectionString"));
            this.dgRegList.DataManager = this.DataManager;

            if (!this.IsPostBack)
            {
                this.txtStartDate.Text = DateTime.Now.ToString("yyyy-MM-01");
                this.txtEndDate.Text = DateTime.Now.ToString("yyyy-MM-dd");
                this.txtUser.Text = this.LogonUser.UserID.ToLower().Trim().Replace("centaline\\", "");

                this.BindLstHolidayType();
                this.BindList();
            }
            
        }

        private void BindList()
        {
            try
            {
                string strFilter = "";
                if (this.txtStartDate.Text != "")
                {
                    strFilter += String.Format(@" And b_date >='{0}'", this.txtStartDate.Text.Trim());
                }
                if (this.txtEndDate.Text != "")
                {
                    strFilter += String.Format(@" And b_date <='{0}'", this.txtEndDate.Text.Trim());
                }
                if (this.lstHolidayType.SelectedValue != "")
                {
                    strFilter += string.Format(@" And Holiday_Identify = '{0}'", this.lstHolidayType.SelectedValue);
                }
                strFilter += String.Format(@" And (DomainAccount = 'centaline\{0}' Or Name = '{0}')", this.txtUser.Text.Trim());

                this.dgRegList.DataSourceTable = "ViewEmployeeHolidayListForMSN";
                this.dgRegList.DataSourceFilter = strFilter;
                this.dgRegList.BindData();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        private void BindLstHolidayType()
        {
            string sql = "";
            try
            {
                sql = "Select HolidayIdentify,HolidayName From T_CHolidayType (nolock)";
                this.DataManager.BindWebDropDownList(this.lstHolidayType, "HolidayName", "HolidayIdentify", sql, "全部");
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }

        protected void dgRegList_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
            #region
            /*
            if (e.Item.ItemIndex >= 0)
            {
                string UserName = "";
                string Register_Date = "";
                string FlowRowID = "";
                string Holiday_Identify = "";
                string DomainAccount = "";

                string bdate = "";
                string edate = "";

                if (e.Item.ItemIndex >= 0)
                {
                    if (e.Item.Cells[3].Text == "通过/有效")
                    {
                        bdate = e.Item.Cells[1].Text;
                        edate = e.Item.Cells[2].Text;

                        Register_Date = e.Item.Cells[4].Text;
                        FlowRowID = e.Item.Cells[5].Text;
                        Holiday_Identify = e.Item.Cells[6].Text;
                        DomainAccount = e.Item.Cells[7].Text;
                        DomainAccount = DomainAccount.ToLower();
                        DomainAccount = DomainAccount.Replace("centaline\\", "");

                        e.Item.Cells[3].CssClass = "tdActionOut";
                        e.Item.Cells[3].Attributes["onMouseOver"] = "this.className='tdActionOver';";
                        e.Item.Cells[3].Attributes["onMouseOut"] = "this.className='tdActionOut';";

                        string url = System.Configuration.ConfigurationManager.AppSettings.Get("KQFlowChangePlan");

                        url = url.Replace("?", "");

                        UserName = Page.User.Identity.Name;

                        url = url + "?RegDate=" + Register_Date;
                        url = url + "&bdate=" + bdate;
                        url = url + "&edate=" + edate;
                        url = url + "&FlowRowID=" + FlowRowID;
                        url = url + "&Holiday_Identify=" + Holiday_Identify;
                        url = url + "&DomainAccount=" + DomainAccount;

                        e.Item.Cells[3].Attributes.Add("onclick", "javascript:window.open('" + url + "','','scrollbars=yes,resizable=yes,status=yes,toolbar=no,menubar=no,location=no')");
                        e.Item.Cells[3].Attributes["title"] = "发起变更单据申请";
                    }

                }
            }
            */
            #endregion
        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            this.BindList();
        }
        
    }
}